package ATM;

import ATM.FixConnection;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author User
 */
public class FixConnection extends javax.swing.JFrame {

    JFileChooser chooser;

    /** Creates new form FixConnection */
    public FixConnection() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtSever = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtLocalhost = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtPort = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtDB = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtID = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtPass = new javax.swing.JTextField();
        btnSave = new javax.swing.JButton();
        btnDefault = new javax.swing.JButton();
        btnClear = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new java.awt.FlowLayout());

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Create File Connection", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 18), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanel1.setMaximumSize(new java.awt.Dimension(400, 400));
        jPanel1.setMinimumSize(new java.awt.Dimension(400, 400));
        jPanel1.setPreferredSize(new java.awt.Dimension(400, 400));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Server :");
        jLabel1.setPreferredSize(new java.awt.Dimension(100, 14));
        jPanel1.add(jLabel1);

        txtSever.setText("jdbc:sqlserver");
        txtSever.setPreferredSize(new java.awt.Dimension(200, 20));
        txtSever.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtSeverMouseClicked(evt);
            }
        });
        jPanel1.add(txtSever);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Localhost :");
        jLabel5.setPreferredSize(new java.awt.Dimension(100, 14));
        jPanel1.add(jLabel5);

        txtLocalhost.setText("localhost");
        txtLocalhost.setPreferredSize(new java.awt.Dimension(200, 20));
        txtLocalhost.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtLocalhostMouseClicked(evt);
            }
        });
        jPanel1.add(txtLocalhost);

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Port :");
        jLabel6.setPreferredSize(new java.awt.Dimension(100, 14));
        jPanel1.add(jLabel6);

        txtPort.setText("1433");
        txtPort.setPreferredSize(new java.awt.Dimension(200, 20));
        txtPort.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtPortMouseClicked(evt);
            }
        });
        jPanel1.add(txtPort);

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Database name :");
        jLabel2.setPreferredSize(new java.awt.Dimension(100, 14));
        jPanel1.add(jLabel2);

        txtDB.setText("ATM");
        txtDB.setPreferredSize(new java.awt.Dimension(200, 20));
        txtDB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtDBMouseClicked(evt);
            }
        });
        jPanel1.add(txtDB);

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("ID :");
        jLabel3.setPreferredSize(new java.awt.Dimension(100, 14));
        jPanel1.add(jLabel3);

        txtID.setText("as");
        txtID.setPreferredSize(new java.awt.Dimension(200, 20));
        txtID.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtIDMouseClicked(evt);
            }
        });
        jPanel1.add(txtID);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Pass :");
        jLabel4.setPreferredSize(new java.awt.Dimension(100, 14));
        jPanel1.add(jLabel4);

        txtPass.setText("123456");
        txtPass.setPreferredSize(new java.awt.Dimension(200, 20));
        txtPass.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txtPassMouseClicked(evt);
            }
        });
        txtPass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPassActionPerformed(evt);
            }
        });
        jPanel1.add(txtPass);

        btnSave.setText("Save");
        btnSave.setPreferredSize(new java.awt.Dimension(80, 23));
        btnSave.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnSaveMouseClicked(evt);
            }
        });
        jPanel1.add(btnSave);

        btnDefault.setText("Default");
        btnDefault.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnDefaultMouseClicked(evt);
            }
        });
        jPanel1.add(btnDefault);

        btnClear.setText("Clear");
        btnClear.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnClearMouseClicked(evt);
            }
        });
        jPanel1.add(btnClear);

        getContentPane().add(jPanel1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txtSeverMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtSeverMouseClicked
        // TODO add your handling code here:
        txtSever.setEnabled(true);
    }//GEN-LAST:event_txtSeverMouseClicked

    private void txtLocalhostMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtLocalhostMouseClicked
        // TODO add your handling code here:
        txtLocalhost.setEnabled(true);
    }//GEN-LAST:event_txtLocalhostMouseClicked

    private void txtPortMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtPortMouseClicked
        // TODO add your handling code here:
        txtPort.setEnabled(true);
    }//GEN-LAST:event_txtPortMouseClicked

    private void txtDBMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtDBMouseClicked
        // TODO add your handling code here:
        txtDB.setEnabled(true);
    }//GEN-LAST:event_txtDBMouseClicked

    private void txtIDMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtIDMouseClicked
        // TODO add your handling code here:
        txtID.setEnabled(true);
    }//GEN-LAST:event_txtIDMouseClicked

    private void txtPassMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txtPassMouseClicked
        // TODO add your handling code here:
        txtPass.setEnabled(true);
    }//GEN-LAST:event_txtPassMouseClicked

    private void btnSaveMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnSaveMouseClicked
        // TODO add your handling code here:
        try {
            BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\Connection.txt"));
            bw.write("server=" + txtSever.getText() + "://" + txtLocalhost.getText() + ":" + txtPort.getText() + ";");
            bw.newLine();
            bw.write("db=DatabaseName=" + txtDB.getText());
            bw.newLine();
            bw.write("id=" + txtID.getText());
            bw.newLine();
            bw.write("pass=" + txtPass.getText());
            bw.close();
            JOptionPane.showMessageDialog(this, "Create completed in 'D:\\Connection.txt' ! Please close system snd try again !");
            this.setVisible(false);
        } catch (IOException ex) {
            Logger.getLogger(connecDB.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnSaveMouseClicked

    private void btnDefaultMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnDefaultMouseClicked
        // TODO add your handling code here:
        txtSever.setText("jdbc:sqlserver");
        txtLocalhost.setText("localhost");
        txtPort.setText("1433");
        txtDB.setText("ATM");
        txtID.setText("sa");
        txtPass.setText("sa");
    }//GEN-LAST:event_btnDefaultMouseClicked

    private void btnClearMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnClearMouseClicked
        // TODO add your handling code here:
        txtSever.setText("");
        txtLocalhost.setText("");
        txtPort.setText("");
        txtDB.setText("");
        txtID.setText("");
        txtPass.setText("");
    }//GEN-LAST:event_btnClearMouseClicked

    private void txtPassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPassActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPassActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnClear;
    private javax.swing.JButton btnDefault;
    private javax.swing.JButton btnSave;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txtDB;
    private javax.swing.JTextField txtID;
    private javax.swing.JTextField txtLocalhost;
    private javax.swing.JTextField txtPass;
    private javax.swing.JTextField txtPort;
    private javax.swing.JTextField txtSever;
    // End of variables declaration//GEN-END:variables
}
